package com.nov.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.web.util.IntrospectorCleanupListener;

@Configuration
public class RedisConfiguration {

    private RedisConnectionFactory redisConnectionFactory;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public RedisConfiguration(RedisConnectionFactory redisConnectionFactory) {
        this.redisConnectionFactory = redisConnectionFactory;
    }

    @Bean
    public CustomRedisTemplate customRedisTemplate() {
        CustomRedisTemplate template = new CustomRedisTemplate(redisConnectionFactory);
        return template;
    }

    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean1() {
        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
        servletListenerRegistrationBean.setListener(new IntrospectorCleanupListener());
        servletListenerRegistrationBean.setOrder(0);
        return servletListenerRegistrationBean;
    }

}
